Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup InsertEnter autocmd after LspAttach event has fired #62

Closed

Conversation

tvercruyssen
Copy link
Contributor

Use case

If you want to only load (work) cmp-nvim-lsp when the LspAttach autocmd fires, but always need to setup the capabilities.
Currently you cannot get the default (lsp) capabilities (require("cmp_nvim_lsp").default_capabilities()) without setting up the entire plugin (=autocmd are created, etc...) (specifically for plugin managers that will source the after directory).

Solution

Make the plugin be lazy in the sense that you can call setup but it won't do anything untill the LspAttach autocmd event fires, which means their is an lsp client attached to a buffer.

Notes!

The LspAttach autocmd event was only introduced in this neovim commit, which is only part of version 0.8.
I think currently this plugin supports 0.7 still? So if we decide we want this we should announce it on #38.

@tvercruyssen tvercruyssen changed the title Only setup InsertEnter autocmd after LspAttach event fired Only setup InsertEnter autocmd after LspAttach event has fired Sep 2, 2023
@tvercruyssen tvercruyssen changed the title Only setup InsertEnter autocmd after LspAttach event has fired Setup InsertEnter autocmd after LspAttach event has fired Sep 2, 2023
@wookayin
Copy link
Contributor

I guess this will break the behavior; what if a buffer is already open and attached, and cmp (cmp-nvim-lsp) loads lazily? the LspAttach autocmd handler won't be called, right?

@tvercruyssen
Copy link
Contributor Author

Yea, I forgot about when you don't just load the plugin at startup....
maybe we keep the original setup function, but introduce a new setup_lazy function instead that would still solve my problem and be backwards compatible

@wookayin
Copy link
Contributor

I actually have a hard time understanding what this PR tries to fix. Could you elaborate? What happens to require("cmp_nvim_lsp").default_capabilities() if some plugins are not loaded there yet?

@tvercruyssen
Copy link
Contributor Author

I actually have a hard time understanding what this PR tries to fix. Could you elaborate? What happens to require("cmp_nvim_lsp").default_capabilities() if some plugins are not loaded there yet?

The problem was that if you (want to) do require("cmp_nvim_lsp"), then you have to load the plugin, which used to cause errors if no LSP functionality was loaded... I don't lazy load LSP functionality anymore, so this is no longer a problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants